<!--
 * @Author: CHINAKAIYUAN<sunkaiyuan@namenode.cn>
 * @Date: 2022-02-03 14:41:20
 * @LastEditTime: 2023-02-01 09:21:55
 * @LastEditors: sunkaiyuan sunkaiyuan@namenode.com
 * @Description:   :gridOps="gridOptions" 
-->
<template>
  <el-container style="height: 100%">
    <el-main style="height: 100%">
      <sc-VxeTable
        ref="xGrid1"
        :gridEvts="gridEvents"
        :tablecode="'basedata_unit_archives'"
        :url="this.$API.basedata.unit.list"
      >
      </sc-VxeTable>
    </el-main>
    <save-dialog
      v-if="dialog.save"
      ref="saveDialog"
      @success="handleSuccess"
      @closed="dialog.save = false"
    ></save-dialog>
  </el-container>
</template>
<script>
import SaveDialog from "./save";
export default {
  components: {
    SaveDialog,
  },
  data() {
    return {
      dialog: {
        save: false,
      },
      gridEvents: {
        cellDblclick: ({ row }) => {
          this.edit(row);
        },
        add: () => {
          this.openSave();
        },
        edit: ({ button }) => {
          this.edit(button.selectRecords[0]);
        },
      },
    };
  },
  methods: {
    openSave: function () {
      this.dialog.save = true;
      this.$nextTick(() => {
        this.$refs.saveDialog.open();
      });
    },

    handleSuccess() {
      this.$refs.xGrid1.refresh();
    },
    edit(item) {
      this.dialog.save = true;
      this.$nextTick(() => {
        this.$refs.saveDialog.open("edit").setData(item);
      });
    },
  },
};
</script>
